$(function(){
	//全局变量
			var _url=window.location.href.split('.')[1];
			window.domain_user = "http://user."+_url+".com/";
			window.domain_hlzf = "http://user."+_url+".com/go/hlpay";
			window.domain_help = "http://help.shikee.com/";
			window.domain_bbs = "http://bbs."+_url+".com/";
			window.domain_list = "http://list."+_url+".com/";
			window.domain_pass = "http://pass."+_url+".com/";
			window.domain_zhs_www = "http://www.zhonghuasuan.com";
		    window.domain_zhs_list = "http://list.zhonghuasuan.com";
			window.domain_report = "http://report."+_url+".com/";
			window.domain_reg = "http://reg."+_url+".com/";
			window.domain_login = "http://login."+_url+".com/";
			window.domain_www = "http://www." + _url + ".com/";
			sk.init();
});

// 全局
var sk = (function() {
	var domain = location.host.replace(/.*(\.\w+\.com)/, '$1');
	return {
        init : function() {
        	this.url.reg = window.domain_reg+ 'reg/doreg/?uType=1';
			$(function() {
				sk.user.init();
				$("#j_topNavManuHover").hover(function() {
					$(this).addClass("top-nm-hover");
				}, function() {
					$(this).removeClass("top-nm-hover");
				});
			});

		},
        site : function(site) {
            return 'http://' + site + domain + '/';
        },
        url : {
			reg : ''
		},
		query : function(name) {
			var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
			if (result == null || result.length < 1) {
				return '';
			}

			return result[1];
		},
		cookie : function(name, value, options) {
			if ( typeof value != 'undefined') {
				options = options || {};
				if (value === null) {
					value = '';
					options = $.extend({}, options);
					options.expires = -1;
				}
				var expires = '';
				if (options.expires && ( typeof options.expires == 'number' || options.expires.toUTCString)) {
					var date;
					if ( typeof options.expires == 'number') {
						date = new Date();
						date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
					} else {
						date = options.expires;
					}
					expires = '; expires=' + date.toUTCString();
				}
				var path = options.path ? '; path=' + (options.path) : '';
				var domain = options.domain ? '; domain=' + (options.domain) : '';
				var secure = options.secure ? '; secure' : '';
				document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
			} else {
				var cookieValue = null;
				if (document.cookie && document.cookie != '') {
					var cookies = document.cookie.split(';');
					for (var i = 0; i < cookies.length; i++) {
						var cookie = jQuery.trim(cookies[i]);
						if (cookie.substring(0, name.length + 1) == (name + '=')) {
							cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
							break;
						}
					}
				}
				return cookieValue;
			}
		}
	};
})();

// 用户类
sk.user = (function() {
	var wrap;
	return {
		init : function() {
			wrap = $('#topbar');
			var user = this.info();
			
			//获取搜索推送数据
			wrap.find('.top-nav-other').prepend('<a href="' + domain_help + '">帮助中心</a>');
			wrap.find('.top-nav-other').prepend('<a href="' + domain_hlzf + '">互联支付</a>');
			wrap.find('.top-nav-other').prepend('<a href="' + domain_zhs_www + '">众划算</a>');
			if (window.location.href.indexOf("report") != -1) { 
				wrap.find('.top-nav-other').prepend('<a href="' + domain_www + '">试客联盟</a>');
			}
			right_str = '<dt class="none-border"><a target="_blank" href="'+domain_list+'">免费试用</a></dt>'; 
			right_str += '<dd><a target="_blank" href="'+domain_list+'list-1.html?type=1">试用专区</a></dd>'; 
			right_str += '<dt><a target="_blank" href="'+domain_zhs_www+'">众划算</a></dt>';
			right_str += ' <dd><a target="_blank" href="'+domain_zhs_list+'">商品总汇</a><a target="_blank" href=" '+domain_zhs_www+'/show/">买家晒单</a></dd>'; 
			right_str += '<dt><a target="_blank" href="'+domain_report+'">试用报告</a></dt>'; 
			right_str += '<dt><a target="_blank" href="'+domain_bbs+'">社区</a></dt>';
			right_str += '<dd><a target="_blank" href="'+domain_bbs+'home.php">家园</a><a target="_blank" href="'+domain_bbs+'group.php">圈子</a><a id="myspace"></a></dd>';
			right_str += '<dt><a target="_blank" href="'+domain_bbs+'forum.php">论坛</a></dt>';
			right_str += '<dd><a href="'+domain_bbs+'forum-6207-1.html" target="_blank">我要帮助</a><a href="'+domain_bbs+'forum-167-1.html" target="_blank">试客生活</a>';
			right_str += '<a href="'+domain_bbs+'forum.php?gid=85" target="_blank">商家在线</a>';
			right_str += '<a href="'+domain_bbs+'forum.php?gid=71" target="_blank">课堂</a>';
			right_str += '<a href="'+domain_bbs+'forum.php?gid=95" target="_blank">官方公告</a>';
			right_str += '<a href="'+domain_bbs+'forum-6208-1.html" target="_blank">我要建议</a></dd>';
			wrap.find('.top-nm-bd').prepend(right_str);
			if (!user) {
				wrap.find('.loginInfo').append('您好，欢迎来到试客联盟！请 [<a target="_self" href="' + domain_login + '">登录</a>] [<a target="_self" href="' + domain_reg + '">免费注册</a>] ');
				return;
			}
			//$('#showlogin').hide();
			//$('#showinfo').show();
			var message_url = 'message/', uc = domain_user;
			var html = [];
			var timestamp=Math.round(new Date().getTime()/1000) ;
			html.push('您好，<a title="进入后台" href="', uc, '?time=',timestamp,'">', user.name, '</a>');
			if(user.type==1){
				html.push(' <span class="topbar-tipMsg">您有未读提醒<a href="', uc, 'buyer/message/">(<em>0</em>)</a>条</span>');
			}else if(user.type==2){
				html.push(' <span class="topbar-tipMsg">您有未读提醒<a href="', uc,  'seller/message/">(<em>0</em>)</a>条</span>');
			}
			html.push(' <a href="', domain_login, 'logout/?to=', window.location.href, '" target="_self">[ 退出 ]</a>');
			wrap.find('.loginInfo').html(html.join(''));
			this.updateMsg();
			if(user.type==1){
				wrap.find('.top-nav-other').prepend('<a href="' + domain_user + 'buyer/report/mylist">我的试用报告</a>');	
			}else if(user.type==2){
				wrap.find('.top-nav-other').prepend('<a href="' + domain_user + 'seller/tryings/add_try_base">发布试用品</a>');
			}
			wrap.find('.top-nav-other').prepend('<a href="' + uc + '?time='+timestamp+'">我的联盟</a>');

		},
		info : function() {
			var cookie = sk.cookie('shikee');
			if (!cookie || cookie.split('|').length != 3) {
				return null;
			}
			var info = cookie.split('|');
			return {
				name : info[0],
				type : info[1]
			};
		},
		updateMsg : function() {
			$.getJSON(sk.site('www') + 'get_stat/?type=msg&callback=?', function(data) {
				if (!data.error) {
					if(data.msg_unread >0)
					{
						wrap.find('.topbar-tipMsg a').html("(<strong class='fc-f4'>"+data.msg_unread+"</strong>)");
					}else{
						wrap.find('.topbar-tipMsg a em').html(data.msg_unread);
					}
				}
			});
		},
		login : function(url) {
			var login_url = domain_login +'login/winlogin?url='+url;
			 Kee.use('artDialog', 'artDialogTools', function () {
				art.dialog.open(login_url,{
					id : 'win-login',
					lock : true,
                    fixed :true,
                    drag : false,
					opacity: 0.6,
					width: '300px',
					height: '270px',
					title : '欢迎登录试客联盟'
				});
			})
		}
	};
})();

//百度统计
// window.onload = function () {
//     var _hmt = _hmt || [];
    /*(function() {
        var hm = document.createElement("script");
        hm.src = "//hm.baidu.com/hm.js?683a19e08e3b71b4c2a63f0d04830141";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();*/
// };